﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using VietKinsNutrition.Bussiness;

namespace VietKinsNutrition.UserControl
{
    public partial class FrmTonghopthu_chi : DevExpress.XtraEditors.XtraUserControl
    {
        bool bTrangthai = false;
        ClsTblDiemdanhtreanBLL ClsTblDiemdanhtreanbll = new ClsTblDiemdanhtreanBLL();
        ClsKhauphandinhduongtrongtuanBLL ClsKhauphandinhduongtrongtuan_bll = new ClsKhauphandinhduongtrongtuanBLL();
        ClsTblDm_NhapthucphamBLL ClsTblDm_Nhapthucphambll = new ClsTblDm_NhapthucphamBLL();
        
        public FrmTonghopthu_chi()
        {
            InitializeComponent();
        }

        private void FrmTonghopthu_chi_Load(object sender, EventArgs e)
        {
            datTu.EditValue = DateTime.Now;
            DateTime dateDen = DateTime.Now;
            int cSunday = 0;
            for (int i = 0; i < 7; i++)
            {
                DateTime dayShow = datTu.DateTime.AddDays(i + cSunday);
                if (dayShow.DayOfWeek == DayOfWeek.Sunday)
                {
                    cSunday += 1;
                    dayShow = dayShow.AddDays(1);
                }
                dateDen = DateTime.Parse(dayShow.Day.ToString() + "/" + dayShow.Month.ToString() + "/" + dayShow.Year.ToString());
            }
            datDen.EditValue = dateDen;
            cboChonmuc.SelectedIndex = 0;
        }
        private void cboChonmuc_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (cboChonmuc.SelectedIndex == 0)
            {
                bTrangthai = false;
                gridView1.Columns["NgayNX"].Caption = "Ngày xuất";
                gridView1.Columns["Soluong"].Caption = "Số lượng xuất";
            }
            else
            {
                bTrangthai = true;
                gridView1.Columns["NgayNX"].Caption = "Ngày nhập";
                gridView1.Columns["Soluong"].Caption = "Số lượng nhập";
            }
            datTu_EditValueChanged(sender, e);
        }

        private void datTu_EditValueChanged(object sender, EventArgs e)
        {
            if (datTu.DateTime < datDen.DateTime)
            {
                gridView1.GridControl.DataSource = ClsTblDm_Nhapthucphambll.Tbl_Tonghopthu_chi(bTrangthai, datTu.DateTime, datDen.DateTime);
            }
            else if (datTu.DateTime == datDen.DateTime)
            {
                return;
            }
            else
                return;
        }

        private void datDen_EditValueChanged(object sender, EventArgs e)
        {
            datTu_EditValueChanged(sender, e);
        }

        DataRow dr;
        string sTieude, sTenso, sTentruong, sTenphong;
        private void btnIn_Click(object sender, EventArgs e)
        {
            if (gridView1.RowCount <= 0)
                return;
            ClsTblTruonghocBLL ClsTblTruonghocbll = new ClsTblTruonghocBLL();
            DataTable Tbl = ClsTblTruonghocbll.ReturnTblTRuong();
            ClsExport2ExcelBLL ClsExport2Excelbll = new ClsExport2ExcelBLL();
            if (Tbl.Rows.Count > 0)
            {
                dr = Tbl.Rows[0];
                sTenso = dr["TensoGD"].ToString();
                sTentruong = dr["Tentruong"].ToString();
                sTenphong = dr["TenphongGD"].ToString();
                sTieude = cboChonmuc.Text.ToUpper();
            }

            DataTable tg = (DataTable)(gridView1.GridControl.DataSource);
            DataTable tblthuchi = tg.Copy();
            System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("VietKinsNutrition.Resources." + "tong hop thu chi.xls");
            ClsDanhsachNV.Tonghopthuchi(stream, "tong hop thu chi.xls", sTenso, sTenphong, sTentruong, sTieude, tblthuchi);
        }
    }
}
